package com.pda.gongpin.utils;

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.zhouwei.library.CustomPopWindow;

import com.pda.gongpin.R;
import com.pda.gongpin.adapter.SelectAdapter;
import com.pda.gongpin.adapter.SelectChildrenAdapter;
import com.pda.gongpin.adapter.SelectNewAdapter;
import com.pda.gongpin.adapter.SelectRawAdapter;
import com.pda.gongpin.bean.DropDownByEntryNoBean;
import com.pda.gongpin.bean.ProductModelBean;
import com.pda.gongpin.bean.RawMaterialTypeBean;
import com.pda.gongpin.bean.SelectBean;
import com.pda.gongpin.bean.SkuBean;


import java.util.List;

public class PopUtisl {
    public static void showChildrenPop(Activity mActivity, List<ProductModelBean> list, View mview, ChildrenClick onItemClick, String title){
        View view = LayoutInflater.from(mActivity).inflate(R.layout.pop_select, null);
        RecyclerView rvContent=view.findViewById(R.id.rv_content);
        TextView tvTitle=view.findViewById(R.id.tv_title);
        ImageView ivClose=view.findViewById(R.id.iv_close);
        tvTitle.setText(title);
        SelectChildrenAdapter adapter = new SelectChildrenAdapter(R.layout.item_pop_select,list);
        rvContent.setAdapter(adapter);
        CustomPopWindow popWindow = new CustomPopWindow.PopupWindowBuilder(mActivity).size(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT)
                .setView(view)//显示的布局
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAtLocation(mview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        CustomPopWindow finalPopWindow = popWindow;
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                onItemClick.onClick(list.get(position));
                finalPopWindow.dissmiss();
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalPopWindow.dissmiss();
            }
        });
    }
    public static void showSelectPop(Activity mActivity, List<DropDownByEntryNoBean> list, String id,View mview, SelectRawClick onItemClick, String title){
        View view = LayoutInflater.from(mActivity).inflate(R.layout.pop_select, null);
        RecyclerView rvContent=view.findViewById(R.id.rv_content);
        TextView tvTitle=view.findViewById(R.id.tv_title);
        ImageView ivClose=view.findViewById(R.id.iv_close);
        tvTitle.setText(title);
        SelectRawAdapter adapter = new SelectRawAdapter(R.layout.item_pop_select,list,id);
        rvContent.setAdapter(adapter);
        CustomPopWindow popWindow = new CustomPopWindow.PopupWindowBuilder(mActivity).size(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT)
                .setView(view)//显示的布局
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAtLocation(mview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        CustomPopWindow finalPopWindow = popWindow;
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                onItemClick.onClick(list.get(position));
                finalPopWindow.dissmiss();
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalPopWindow.dissmiss();
            }
        });
    }
    public static void showSelectPop(Activity mActivity, List<SkuBean> list, View mview, SelectSkuClick onItemClick, String title){
        View view = LayoutInflater.from(mActivity).inflate(R.layout.pop_select, null);
        RecyclerView rvContent=view.findViewById(R.id.rv_content);
        TextView tvTitle=view.findViewById(R.id.tv_title);
        ImageView ivClose=view.findViewById(R.id.iv_close);
        tvTitle.setText(title);
        SelectAdapter adapter = new SelectAdapter(R.layout.item_pop_select,list);
        rvContent.setAdapter(adapter);
        CustomPopWindow popWindow = new CustomPopWindow.PopupWindowBuilder(mActivity).size(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT)
                .setView(view)//显示的布局
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAtLocation(mview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        CustomPopWindow finalPopWindow = popWindow;
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                onItemClick.onClick(list.get(position));
                finalPopWindow.dissmiss();
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalPopWindow.dissmiss();
            }
        });
    }
    public static void showSelectPop(Activity mActivity, List<SelectBean> list, View mview, SelectClick onItemClick, String title){
        View view = LayoutInflater.from(mActivity).inflate(R.layout.pop_select, null);
        RecyclerView rvContent=view.findViewById(R.id.rv_content);
        TextView tvTitle=view.findViewById(R.id.tv_title);
        ImageView ivClose=view.findViewById(R.id.iv_close);
        tvTitle.setText(title);
        SelectNewAdapter adapter = new SelectNewAdapter(R.layout.item_pop_select,list);
        rvContent.setAdapter(adapter);
        CustomPopWindow popWindow = new CustomPopWindow.PopupWindowBuilder(mActivity).size(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT)
                .setView(view)//显示的布局
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAtLocation(mview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        CustomPopWindow finalPopWindow = popWindow;
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                onItemClick.onClick(list.get(position));
                finalPopWindow.dissmiss();
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finalPopWindow.dissmiss();
            }
        });
    }
    public  interface SelectClick{
        void onClick(SelectBean bean);
    }
    public  interface SelectSkuClick{
        void onClick(SkuBean bean);
    }
    public  interface ChildrenClick{
        void onClick(ProductModelBean bean);
    }
    public  interface SelectRawClick{
        void onClick(DropDownByEntryNoBean bean);
    }
}
